<template>
    <div class="community-nav">
        <div
            :class="['community-nav-item', { active: activeIndex === index }]"
            v-for="(nav, index) in navs"
            :key="index"
            @click="navClick(index)"
        >
            {{ nav.title }}
        </div>
    </div>
</template>

<script>
export default {
    name: 'DuoduocaiH5CommunityNav',
    props: {
        navs: {
            type: Array,
            default() {
                return [];
            },
        },
        activeItem: [String, Number],
    },
    computed: {
        activeIndex: {
            set(val) {
                this.$emit('update:activeItem', val);
            },
            get() {
                return this.activeItem;
            },
        },
    },
    data() {
        return {};
    },

    mounted() {},

    methods: {
        navClick(index) {
            console.log('🚀 ~ file: community-nav.vue ~ line 46 ~ navClick ~ index', index);
            // eslint-disable-next-line vue/no-mutating-props
            this.$emit('update:activeItem', index);
        },
    },
};
</script>

<style lang="scss" scoped>
.community-nav {
    display: flex;
    padding: 0 10px;
    background: white;
    .community-nav-item {
        width: 33%;
        text-align: center;
        line-height: 50px;
    }
    .active {
        color: red;
    }
}
</style>
